<?php


namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

class Sample extends Api
{
    /**
     * 
     */
    public function from_teacher()
    {
        if ($this->request->isPost()) {
                $params = $this->request->post("row/a");
                print_r(1111111111);die;
                if ($params) {
                    //通过
                    $params2  = GenerateWeek();
                    //print_r($params2);die;
                    if(empty($params2)) $this->error(__('You have no permission or data already exists'));
                    //合并数据
                    $params = array_merge($params,$params2);
                    //print_R($params);die;
                    if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
                        $params[$this->dataLimitField] = $this->auth->id;
                    }
                    try {
                        //是否采用模型验证
                        if ($this->modelValidate) {
                            $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                            $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
                            $this->model->validate($validate);
                        }
                        $result = $this->model->allowField(true)->save($params);
                        if ($result !== false) {
                            //生成周默认成员
                            model(GetTableModel('User'))->saveAll(GenerateWeekUser($this->model->id));
                            $this->success();
                        } else {
                            $this->error($this->model->getError());
                        }
                    } catch (\think\exception\PDOException $e) {
                        $this->error($e->getMessage());
                    }
                }
                $this->error(__('Parameter %s can not be empty', ''));
            }
        $this->success('', $provincelist);
    }
}